package windows;

import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

public class MainFrame {
	private JFrame frame = new JFrame("Carduri salariu");
	private JComboBox comboBox_Scoala = new JComboBox();
	private JButton okButton = new JButton("Ok");
	private JButton addSchoolButton = new JButton("Adauga scoala");
	private JButton removeSchoolButton = new JButton("Sterge scoala");
	private JButton loadDatabaseButton = new JButton("Importa baza de date");
	private JButton exportDatabaseButton = new JButton("Exporta baza de date");
	private JTextField textField_SchoolName = new JTextField();

	public JButton getAddSchoolButton() {
		return addSchoolButton;
	}

	public JComboBox getComboBox_Scoala() {
		return comboBox_Scoala;
	}

	public JButton getExportDatabaseButton() {
		return exportDatabaseButton;
	}

	public JFrame getFrame() {
		return frame;
	}

	public JButton getLoadDatabaseButton() {
		return loadDatabaseButton;
	}

	public JButton getOkButton() {
		return okButton;
	}

	public JButton getRemoveSchoolButton() {
		return removeSchoolButton;
	}

	public JTextField getTextField_SchoolName() {
		return textField_SchoolName;
	}

	public void hideFrame() {
		frame.setVisible(false);

	}

	public void setFrame() {
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JPanel leftPanel = new JPanel();
		JPanel rightPanel = new JPanel();
		SpringLayout layout = new SpringLayout();
		SpringLayout layout1 = new SpringLayout();
		leftPanel.setLayout(layout);
		rightPanel.setLayout(layout1);

		JLabel _labelAddScoala_mainFrame = new JLabel(
				"Introduceti numele scolii:");
		JLabel _labelSelectScoala_mainFrame = new JLabel("Selectati scoala");

		leftPanel.add(_labelSelectScoala_mainFrame);
		leftPanel.add(comboBox_Scoala);
		leftPanel.add(okButton);
		leftPanel.add(removeSchoolButton);

		leftPanel.add(_labelAddScoala_mainFrame);
		leftPanel.add(textField_SchoolName);
		leftPanel.add(addSchoolButton);
		leftPanel.add(loadDatabaseButton);
		leftPanel.add(exportDatabaseButton);
		

		okButton.setPreferredSize(new Dimension(120, 30));
		okButton.setActionCommand("selectSchoolCommand");

		addSchoolButton.setPreferredSize(new Dimension(120, 30));
		addSchoolButton.setActionCommand("addSchoolCommand");

		removeSchoolButton.setPreferredSize(new Dimension(120, 30));
		removeSchoolButton.setActionCommand("removeSchoolCommand");
		
		loadDatabaseButton.setPreferredSize(new Dimension(180,30));
		loadDatabaseButton.setActionCommand("loadDatabaseCommand");
		
		exportDatabaseButton.setPreferredSize(new Dimension(180,30));
		exportDatabaseButton.setActionCommand("exportDatabaseCommand");

		comboBox_Scoala.setPreferredSize(new Dimension(300, 30));
		comboBox_Scoala.setEditable(false);

		textField_SchoolName.setPreferredSize(new Dimension(300, 30));

		layout.putConstraint(SpringLayout.WEST, _labelSelectScoala_mainFrame,
				140, SpringLayout.WEST, leftPanel);
		layout.putConstraint(SpringLayout.NORTH, _labelSelectScoala_mainFrame,
				30, SpringLayout.NORTH, leftPanel);

		layout.putConstraint(SpringLayout.WEST, comboBox_Scoala, 35,
				SpringLayout.WEST, leftPanel);
		layout.putConstraint(SpringLayout.NORTH, comboBox_Scoala, 5,
				SpringLayout.SOUTH, _labelSelectScoala_mainFrame);

		layout.putConstraint(SpringLayout.WEST, okButton, 60,
				SpringLayout.WEST, leftPanel);
		layout.putConstraint(SpringLayout.NORTH, okButton, 5,
				SpringLayout.SOUTH, comboBox_Scoala);

		layout.putConstraint(SpringLayout.WEST, removeSchoolButton, 5,
				SpringLayout.EAST, okButton);
		layout.putConstraint(SpringLayout.NORTH, removeSchoolButton, 5,
				SpringLayout.SOUTH, comboBox_Scoala);

		layout.putConstraint(SpringLayout.WEST, _labelAddScoala_mainFrame, 170,
				SpringLayout.EAST, comboBox_Scoala);
		layout.putConstraint(SpringLayout.NORTH, _labelAddScoala_mainFrame, 30,
				SpringLayout.NORTH, leftPanel);

		layout.putConstraint(SpringLayout.WEST, textField_SchoolName, 80,
				SpringLayout.EAST, comboBox_Scoala);
		layout.putConstraint(SpringLayout.NORTH, textField_SchoolName, 5,
				SpringLayout.SOUTH, _labelAddScoala_mainFrame);

		layout.putConstraint(SpringLayout.WEST, addSchoolButton, 170,
				SpringLayout.EAST, comboBox_Scoala);
		layout.putConstraint(SpringLayout.NORTH, addSchoolButton, 5,
				SpringLayout.SOUTH, textField_SchoolName);
		
		layout.putConstraint(SpringLayout.WEST, exportDatabaseButton, 187,
				SpringLayout.WEST, leftPanel);
		layout.putConstraint(SpringLayout.NORTH, exportDatabaseButton, 30,
				SpringLayout.SOUTH, okButton);

		layout.putConstraint(SpringLayout.WEST, loadDatabaseButton, 15,
				SpringLayout.EAST, exportDatabaseButton);
		layout.putConstraint(SpringLayout.NORTH, loadDatabaseButton, 30,
				SpringLayout.SOUTH, okButton);
		frame.getContentPane().add(leftPanel);

	//	frame.setDefaultLookAndFeelDecorated(true);
		frame.setSize(780, 250);
		frame.setMinimumSize(new Dimension(780, 200));
		frame.setVisible(true);

	}

	public void showError(String error) {

		JOptionPane.showMessageDialog(frame, error, "Error",
				JOptionPane.ERROR_MESSAGE);

	}

	public void showFrame() {
		frame.setVisible(true);

	}
}